<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>01立即监听</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>
    <div id="demo">
        <h1>天气切换{{isFost}}</h1>
        <button @click="changeWeather">切换天气</button>
        <img :src="url" >
    </div>
    <script type="text/javascript">
        Vue.config.productionTip = false
        new Vue({
            el: '#demo',
            data: {
                isHot: true,
                url:'https://s3.ax1x.com/2020/12/13/reC1IA.jpg'
            },
            methods: {
                changeWeather(){
                    this.isHot = !this.isHot 
                }
            },
            computed: {
                isFost(){
                    return this.isHot ? '炎热':'凉爽'
                }
            },
            watch:{
                isHot:{
                    immediate:true,
                    handler(value){
                    if(value) this.url ='https://s3.ax1x.com/2020/12/13/reC1IA.jpg'
                    else this.url = 'https://s3.ax1x.com/2020/12/13/reCaqg.jpg'
                }
            }
         }
    })
    </script>
</body>

</html>